<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- 各种router-link写法 -->
    <!-- 字符串 -->
    <router-link to="/list">文章列表</router-link>
    <router-link to="/article/10001">文章详情</router-link>
    <router-link to="/item?id=10001">文章详情</router-link>
    <hr>
    <!-- 对象 -->
    <router-link :to="{path:'/list'}">文章列表</router-link>
    <router-link :to="{name:'article',params:{id:10001}}">文章列表</router-link>
    <router-link :to="{path:'/item',query:{id:10001}}">文章列表</router-link>

    <!-- 显示路由对应组件容器 -->
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.min.js"></script>
  <script>
    // routes 指定路由规则数组
    const router = new VueRouter({ 
      routes:[
        {
          path: '/list', 
          component: {
            template: `<div>列表组件</div>`
          }
        },
        {
          path: '/article/:id', 
          name: 'article',
          component: {
            template: `<div>article文章详情组件 {{$route.params.id}}</div>`
          }
        },
        {
          path: '/item', 
          component: {
            template: `<div>item文章详情组件 {{$route.query.id}}</div>`
          }
        }
      ] 
    })
    new Vue({
      el: '#app',
      router
    })
  </script>
</body>
</html>